package com.medium.house.service.impl;

import com.medium.house.entity.HouseSellPoint;
import com.medium.house.repository.HouseSellPointMapper;
import com.medium.house.response.HouseCondition;
import com.medium.house.service.HouseSellPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : wang.yu
 * @Description :
 * @Date: Created in 2018/2/27 0027  16:10
 * @Modified By
 */
@Service
public class HouseSellPointServiceImpl implements HouseSellPointService {

    @Autowired
    private HouseSellPointMapper houseSellPointMapper;

    @Override
    public int add(HouseSellPoint dto)
    {
        return houseSellPointMapper.insert(dto);
    }

    @Override
    public int delete(long id)
    {
        return houseSellPointMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(HouseSellPoint dto)
    {
        return houseSellPointMapper.updateByPrimaryKeySelective(dto);
    }

    @Override
    public HouseSellPoint get(long id)
    {
        return houseSellPointMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HouseSellPoint> getByPage(
            int start,
            int limit,
            int orderby,
            int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HouseSellPointMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseSellPointMapper.selectByPage(start, limit, HouseSellPointMapper.ORDERBY[orderby], HouseSellPointMapper.ORDER[order], args);
    }

    @Override
    public List<Long> getIdsByPage(
            int start,
            int limit,
            int orderby,
            int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HouseSellPointMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseSellPointMapper.selectIdsByPage(start, limit, HouseSellPointMapper.ORDERBY[orderby], HouseSellPointMapper.ORDER[order], args);
    }

    @Override
    public long count()
    {
        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseSellPointMapper.count(args);
    }
    @Override
    public List<HouseCondition> getByTypeAndStatus(int type, int status){
        Map<String, Object> args = new HashMap<>();
        if (type > 0) { args.put("type",type);}
        if (status > 0) { args.put("status",status);}
        return houseSellPointMapper.selectByCondition(args);
    }
}
